package marmalius.player;

public class Coordonne {
	private int absX, absY, heightLevel; //absolute
	private int mapRegionX, mapRegionY; //region
	private int currentX, currentY;
	
	public Coordonne (int absX, int absY, int heightLevel) {
		setAbsXYH(absX, absY, heightLevel);
		mapRegionX = -1;
		mapRegionY = -1;
	}
	
	public void setAbsXYH(int absX, int absY, int heightLevel) {
		this.absX = absX;
		this.absY = absY;
		this.heightLevel = heightLevel;
		currentX = absX - mapRegionX * 8;
		currentY = absY - mapRegionY * 8;
	}
	
	public void updateMapRegion() {
		mapRegionX = (absX >> 3) - 6;
		mapRegionY = (absY >> 3) - 6;
	}
	
	public boolean updateMapRegion2() {
		boolean mapRegionDidChange = false;
		byte byte0 = 0;
		byte byte1 = 0;
		if (currentX < 16) {
			byte0 = 32;
			mapRegionX -= 4;
			mapRegionDidChange = true;
		}
		else if (currentX >= 88) {
			byte0 = -32;
			mapRegionX += 4;
			mapRegionDidChange = true;
		}
		if (currentY < 16) {
			byte1 = 32;
			mapRegionY -= 4;
			mapRegionDidChange = true;
		}
		else if (currentY >= 88) {
			byte1 = -32;
			mapRegionY += 4;
			mapRegionDidChange = true;
		}
		if (mapRegionDidChange) {
			currentX += byte0;
			currentY += byte1;
		}
		return mapRegionDidChange;
	}
	
	public int getAbsX() { return absX; }
	public int getAbsY() { return absY; }
	public int getAbsH() { return heightLevel; }
	public int getMapRegionX() { return mapRegionX; }
	public int getMapRegionY() { return mapRegionY; }
	
	public int getCurrentX() { return currentX; }
	public int getCurrentY() { return currentY; }
	
	public int getCurrentObjX(int absX) {
		return absX - mapRegionX * 8;
	}
	public int getCurrentObjY(int absY) {
		return absY - mapRegionY * 8;
	}
}
